package SparkRDD.RDD算子.Transformations.排序操作

import org.apache.spark.{SparkConf, SparkContext}
import org.junit.Test

/*
  * RDD 中的排序操作有 sortBy 和 sortByKey，其中sortBy适用于普通的RDD，sortByKey适用于含有Key-Value键值对的RDD
  *   ascending = true  默认升序  ；ascending = false 降序
 */
class sortByTest {

  val conf = new SparkConf().setMaster("local[6]").setAppName("sortBy")
  val sc   = new SparkContext(conf)

  @Test
  def sortByTest: Unit ={
    val source = sc.parallelize(Seq(22,15,4,33,51,6,1,24,65,100,0))
    source.sortBy(item => item,ascending = false)
      .collect()
      .foreach(println(_))
  }

}
